<?php
use app\models\Mall;
use yii\helpers\Url;

$web = Url::base();
//$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
//$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$institution_code = Mall::getCurrentInstitutionCode();

$this->title = '卡卷详情';
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/virtual-coupon-detail.css"/>
<div class="main">
    <div class="head-img">
        <img src="<?= $goods['info']->picBg ?>"/>
    </div>
    <div class="title">
        <p class="goods-title"><?= $goods['info']->title ?></p>
        <del class="original-price">¥:<?= $goods['info']->price ?></del>
    </div>
    <div class="goods-information">
        <p class="stock">剩余库存<span><?= $goods['amount'] ?></span></p>
        <p class="scope">适用地区<span><?= $goods['districtStr'] ?></span></p>
        <p class="validity">使用有效期<span><?= date('Y-m-d', $goods['info']->dateValidFrom) ?> 至 <?= date('Y-m-d', $goods['info']->dateValidTo) ?></span></p>
        <p class="supplier">供应商<span><?= $goods['info']->brands ?></span></p>
        <p class="add-txt">领取后请仔细查看使用说明以便正确使用</p>
        <a href="http://m.fanso2o.com/shop/<?= $goods['shopId'] ?>" class="get-btn">免费领取</a>
    </div>
    <div class="drag">
        继续拖动，查看图文详情
    </div>
    <div class="explain">
        <p class="title">使用须知</p>
        <div class="content">
            <?= $goods['info']->description ?>
        </div>
    </div>
    <div class="history">
        <p class="f-l">历史足迹</p>
        <img class="f-l" src="<?= $web ?>/images/mall-m/history-icon.png"/>
    </div>
    <div class="goods-container">
        <div class="goods-grid-frame" id="his_goods_grid">
        </div>
    </div>
</div>
<script>
    $(function ($) {
        //展示历史足迹
        if (myStorage) {
            if (myStorage.his_goods_array) {
                var his_goods_array = JSON.parse(myStorage.his_goods_array);
                var data = {};
                data.goods_code_list = his_goods_array;
                requestJsonMallM('get-his-goods-handler', data, true, function (response) {
                    if (response.status == 0) {
                        var goods_list = response.data;
                        var html = '';
                        for (var j = 0; j < his_goods_array.length; j++) {
                            for (var i = 0; i < goods_list.length; i++) {
                                if (his_goods_array[his_goods_array.length - 1 - j] == goods_list[i].code) {
                                    html += '<a class="goods-item" href="goods-detail?institution_code=<?= $institution_code ?>&goods_code=' + goods_list[i].code + '">';
                                    html += '<img src="' + goods_list[i].image_url + '">';
                                    html += '<label class="name">' + goods_list[i].name + '</label>';
                                    html += '<label class="price">' + goods_list[i].integral_unit + ':' + parseInt(goods_list[i].selling_integral) + '</label>';
                                    html += '</a>';
                                    break;
                                }
                            }
                        }
                        $("#his_goods_grid").append(html);
                    }
                });
            }
        }

        //添加当前商品访问记录,显示10个
//        if (myStorage) {
//            var goods_code = "<?//=$goods['code']?>//";
//            if (goods_code) {
//                var his_goods_array = [];
//                var new_goods_array = [];
//                if (myStorage.his_goods_array != undefined) {
//                    his_goods_array = JSON.parse(myStorage.his_goods_array);
//                }
//
//                if (his_goods_array.length > 0) {
//                    //只显示9个
//                    var temp_array = [];
//                    var j = 0;
//                    for (var i = 0; i < his_goods_array.length; i++) {
//                        if (his_goods_array[his_goods_array.length - 1 - i] != goods_code) {
//                            temp_array.push(his_goods_array[his_goods_array.length - 1 - i]);
//                            j = j + 1;
//                            if (j == 9) {
//                                break;
//                            }
//                        }
//                    }
//
//                    for (var i = 0; i < temp_array.length; i++) {
//                        new_goods_array.push(temp_array[temp_array.length - 1 - i]);
//                    }
//                }
//
//                new_goods_array.push(goods_code);
//                myStorage.his_goods_array = JSON.stringify(new_goods_array);
//            }
//        }

    });
</script>
